﻿@model BBICMS.Model.ViewModel.Back.CompanyInfoVM

@{
    
    ViewBag.Title = "公司资料";
    ViewBag.PageTitle = ViewBag.Title + "_常规设置";

}

    <div class="panel panel-default">
        <div class="panel-heading">
            <i class="glyphicon glyphicon-home"></i> @ViewBag.Title
        </div>
        <div class="panel-body">
            @using (Ajax.BeginForm("Company", "Info", new AjaxOptions()
            {
                OnBegin = "onBegin",             
                OnSuccess = "updateSuccess",
                OnComplete = "onComplete"

            }, new { @class = "form-horizontal", role = "form" }))
            {

                @Html.AntiForgeryToken()
                @Html.ValidationSummary()



                <div class="form-group">
                    @Html.LabelFor(model => model.CompanyName, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.CompanyName, new { @class = "form-control", placeholder = "公司名称" })
                        @Html.ValidationMessageFor(model => model.CompanyName)
                    </div>
                   
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.CompanyShortName, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.CompanyShortName, new { @class = "form-control", placeholder = "公司简称" })
                        @Html.ValidationMessageFor(model => model.CompanyShortName)
                    </div>
                   
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Address, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextAreaFor(model => model.Address, new { @class = "form-control", placeholder = "公司地址" })
                        @Html.ValidationMessageFor(model => model.Address)
                    </div>
                  
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Coordinate, new { @class = "col-md-2 control-label" })
                    <div class="col-sm-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.Coordinate, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Coordinate, ViewData).Watermark })
                            <span class="input-group-btn">
                                <button class="btn btn-default" type="button" data-toggle="modal" data-target="#myModal"><span class="glyphicon glyphicon-map-marker"></span> 坐标拾取</button>
                            </span>
                        </div>
                        @Html.ValidationMessageFor(model => model.Coordinate)
                    </div>
                   
                </div>


                <div class="form-group">
                    @Html.LabelFor(model => model.ContactMan, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.ContactMan, new { @class = "form-control", placeholder = "联系人" })
                        @Html.ValidationMessageFor(model => model.ContactMan)
                    </div>
                  
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Mobile, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Mobile, new { @class = "form-control", placeholder = "手机" })
                        @Html.ValidationMessageFor(model => model.Mobile)
                    </div>
                  
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Phone, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Phone, new { @class = "form-control", placeholder = "电话" })
                        @Html.ValidationMessageFor(model => model.Phone)
                    </div>
                 
                </div>


                <div class="form-group">
                    @Html.LabelFor(model => model.Fax, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Fax, new { @class = "form-control", placeholder = "传真" })
                        @Html.ValidationMessageFor(model => model.Fax)
                    </div>
                   
                </div>


                <div class="form-group">
                    @Html.LabelFor(model => model.ZipCode, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.ZipCode, new { @class = "form-control", placeholder = "邮政编码" })
                        @Html.ValidationMessageFor(model => model.ZipCode)
                    </div>
                 
                </div>
                

                <div class="form-group">
                    @Html.LabelFor(model => model.MailTo, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.MailTo, new { @class = "form-control", placeholder = "邮箱" })
                        @Html.ValidationMessageFor(model => model.MailTo)
                    </div>
                 
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.MailCC, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.MailCC, new { @class = "form-control", placeholder = "备用邮箱" })
                        @Html.ValidationMessageFor(model => model.MailCC)
                    </div>
                 
                </div>
                

                <div class="form-group">
                    <div class="col-sm-offset-2 col-md-3">
                        <button type="submit" class="btn btn-primary" ><span class="glyphicon glyphicon-save"></span> 保存资料</button>
                    </div>
                    @*<div class="col-md-7">
                        @TempData["message"]
                    </div>*@
                </div>
            }

        </div>
    </div>



    <!-- Modal 百度地图 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel"><span class="glyphicon glyphicon-map-marker"></span> 百度地图坐标拾取</h4>
            </div>
            <div class="modal-body">
                <div id="allmap" style="width:100%;height:450px;"></div>
                <span class="help-block">
                   *点击地图，会自动获取所点击目标的坐标。
                </span>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
            </div>
        </div>
    </div>
</div>
<!-- end main container -->
@section footer {
   @Scripts.Render("~/bundles/jqueryvalWithBootstrap")

<script src="http://api.map.baidu.com/api?v=2.0&ak=G7h0sKsr60IFU3OrHRmKTRzD"></script>
<script>

    // 百度地图API功能
    var map = new BMap.Map("allmap");


    map.enableScrollWheelZoom(true);
    map.addControl(new BMap.NavigationControl());

    var currentPoint = $('#Coordinate').val();
    if (currentPoint.length > 0) {
        var pt = currentPoint.split(",");
        // alert(parseFloat(pt[0]));
        // alert(parseFloat(pt[1]));
        var point = new BMap.Point(parseFloat(pt[0]), parseFloat(pt[1]));
        map.centerAndZoom(point, 12);
        var marker = new BMap.Marker(point);// 创建标注
        map.addOverlay(marker);             // 将标注添加到地图中

        marker.addEventListener("dragend", function(e) {
            // alert("当前位置：" + e.point.lng + ", " + e.point.lat);
            $('#Coordinate').val(e.point.lng + ", " + e.point.lat);
        });

    } else {

        var point = new BMap.Point(116.331398, 39.897445);
        map.centerAndZoom(point, 12);

        function myFun(result) {
            var cityName = result.name;
            map.setCenter(cityName);
        }
        var myCity = new BMap.LocalCity();
        myCity.get(myFun);
    }



    map.addEventListener("click", function (e) {
        // alert(e.point.lng + "," + e.point.lat);
        map.clearOverlays();
        var marker = new BMap.Marker(e.point);// 创建标注
        map.addOverlay(marker);  // 将标注添加到地图中
        marker.enableDragging();

        var p = marker.getPosition();       //获取marker的位置
        // alert("marker的位置是" + p.lng + "," + p.lat);
        $('#Coordinate').val(p.lng + "," + p.lat);

        marker.addEventListener("dragend", function (e) {
            // alert("当前位置：" + e.point.lng + ", " + e.point.lat);
            $('#Coordinate').val(e.point.lng + ", " + e.point.lat);
        })
    });

    //$('form').validateBootstrap(true);
    function onBegin() {
        $("#divLoading").show();
    }
    function onComplete() {
        $("#divLoading").hide();
    }
    //表单更新
    function updateSuccess(data) {
        Common.ShowBox(data.Status, data.Message, "@ViewBag.Title");
    

      //  debugger;
    }
    $(function () {
        Common.ActiveCurrentNav();
    });
</script>
}
